﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleRest.Core
{
    /// <summary>
    /// Strongly typed class implementing IOperationResponse which the developer can use to add additional response
    /// information from a service operation as well as the value.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class OperationResponse<T> : IOperationResponse
    {
        public string RedirectUrl { get; internal set; }

        public OperationResponse(T content)
        {
            this.Content = content;
            this.StatusCode = System.Net.HttpStatusCode.OK;
        }
        public OperationResponse(T content, System.Net.HttpStatusCode statusCode)
            : this(content)
        {
            this.StatusCode = statusCode;
        }
        public OperationResponse(System.Net.HttpStatusCode statusCode)
        {
            this.StatusCode = statusCode;
        }

        /// <summary>
        /// The value for the associated operation response.
        /// </summary>
        public object Content { get; private set; }
        /// <summary>
        /// The http status code associated to the operation response.
        /// </summary>
        public System.Net.HttpStatusCode StatusCode { get; private set; }

        public static OperationResponse<T> Redirect(string url)
        {
            OperationResponse<T> response = new OperationResponse<T>(System.Net.HttpStatusCode.Redirect);
            response.RedirectUrl = url;
            return response;
        }
    }

    /// <summary>
    /// Strongly typed class implementing IOperationResponse which the developer can use to return a simple status code with no value.
    /// </summary>
    public class OperationResponse : IOperationResponse
    {
        public string RedirectUrl { get; internal set; }

        public OperationResponse(System.Net.HttpStatusCode statusCode)
        {
            this.StatusCode = statusCode;
        }
        /// <summary>
        /// The http status code associated to the operation response.
        /// </summary>
        public System.Net.HttpStatusCode StatusCode { get; private set; }

        /// <summary>
        /// Always null as no type was specified.
        /// </summary>
        public object Content
        {
            get { return null; }
        }

        public static OperationResponse Redirect(string url)
        {
            OperationResponse response = new OperationResponse(System.Net.HttpStatusCode.Redirect);
            response.RedirectUrl = url;
            return response;
        }
    }
}
